<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <canvas id="canvas" style="border:dashed" width="300" height="300"></canvas>
    <script>
        var c = document.getElementById("canvas");
        var ctx = c.getContext("2d");
        ctx.moveTo(10, 40);
        ctx.lineTo(40, 10);
        ctx.lineTo(80, 40);
        ctx.lineTo(120, 10);
        ctx.lineTo(160, 40);
        ctx.lineTo(200, 10);
        //ctx.closePath();
        ctx.lineWidth = 2;
        // ctx.closePath(); /**闭合路径**/
        ctx.strokeStyle = "red"; // 路径填充
        ctx.fillStyle = "green"; //填充图形
        ctx.stroke(); //绘制路径
        //ctx.fill(); //绘制图形
    </script>
</body>

</html>